home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9245 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  46 lines

  1. Path: doc.ic.ac.uk!usenet
  2. From: Ben Jefferys <brj@doc.ic.ac.uk>
  3. Newsgroups: comp.lang.c++
  4. Subject: Saving a C++ object
  5. Date: Thu, 29 Feb 1996 15:33:34 +0000
  6. Organization: Imperial College, Computing Department
  7. Message-ID: <3135C74E.446B9B3D@doc.ic.ac.uk>
  8. NNTP-Posting-Host: oak44.doc.ic.ac.uk
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3_U1 sun4c)
  13.  
  14. When I save a C++ object just using:
  15.  
  16. ----------------------------
  17. class ovoid{
  18. /* etc. */
  19. }
  20.  
  21. ovoid square
  22.  
  23. file.write((unsigned char *) &square, sizeof(ovoid))
  24. ----------------------------
  25.  
  26. What *exactly* is saved? I'm finding that every time I recompile
  27. an application when I've added some new code, trying to load
  28. an object saved in this way with an old version of the application
  29. crashes it, even if the class of the object in question hasn't
  30. changed. I presume there are some pointers or something which are
  31. changing when I add new chunks of code. What can I do to avoid this?
  32.  
  33. (ovoid doesn't containg any explicit pointers which are not reset when
  34. reloading - ie. I'm not trying to use old pointers which have
  35. been saved - not to my knowledge anyway)
  36.  
  37. Also, is there anything dodgy about saving a class from within itself, 
  38. using:
  39.  
  40. file.write((unsigned char *) &this, sizeof(ovoid))
  41.  
  42. Thanks for your help.
  43.  
  44. -- 
  45. Je suis triste et seul ici.
  46.